#!/bin/bash
#########################################
# author:      ljq
# date:        2025-01-18
# describe:
#      postmarketOS 自动化安装配置
#########################################

HOME=/home/user
REPO_DIR=$HOME/public/repo
POSTMARKET_DIR=$REPO_DIR/linux/postmarket


#if false; then

if [ `whoami` != 'root' ];then
		echo -e "\e[1;33;41m error:  \e[0m  please run  as  root "
        # exit的值只能在0~255之间,除了0其它都是表示失败
        exit 1
fi

if [ -d $POSTMARKET_DIR ]; then
    echo "已经初始化过, 无须再初始化"
	exit 1
fi


echo '[-] 开始安装基础软件.....'
apk add   make  gcc  g++ 
apk add  curl  vim  git  flatpak


echo '[-] 安装配置ssh.......'
apk add openssh 
echo "设置 ssh 开机自启"
rc-service sshd start
# 设置开机启动
rc-update add sshd

#echo '[-] 安装配置防火墙.....'
#apk  add  awall




sudo -u user bash <<EOF

echo "[-] 创建基本目录 $REPO_DIR"
mkdir -p  $REPO_DIR 
cd  ${REPO_DIR}


echo "[-] 添加远程数据到目录......"
git clone https://gitee.com/ljq199612/mobileOS.git
git clone https://gitee.com/ljq199612/Volumn.git

# ====================================================================================================

echo "[-] 配置国内源......"
mv /etc/apk/repositories  /etc/apk/repositories.bak
ln -s  ${POSTMARKET_DIR}/_/etc/apk/repositories  /etc/apk/repositories
apk update

echo "配置全局环境......"
rm /etc/profile.d/bashrc.sh
ln -s  ${POSTMARKET_DIR}/_/etc/profile     /etc/profile.d/bashrc.sh
source /etc/profile

echo " done !!!"






echo ================================= docker 安装及配置 =====================================
apk add docker


